﻿package mortal.game.view.mount.newMountModuel
{
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.mount.data.*;
    import mortal.game.view.mount.panel.*;
    import mortal.game.view.wizard.panel.*;
    import mortal.mvc.core.*;

    public class MountEquipPart extends GSprite
    {
        private var _mountItemSp:GSprite;
        private var _grouthOpenTips:GTextFiled;
        private var _talentItemTips:GTextFiled;
        private var _mountGrouthUseBtn:GLoadedButton;
        private var _mountTalentUseBtn:GLoadedButton;
        private var _mountGrouthItem:BaseItem;
        private var _mountTalentItem:BaseItem;
        protected var _wardrobeEnterBtn:GLoadingButton;
        private var _mountSharpItem:OtherEquipItem;
        private var _mountEquipMentList:Vector.<OtherEquipItem>;
        private var _mountData:MountData;
        public static const grouthItemCode:int = 410390001;
        public static const tatlentItemCode:int = 410350001;

        public function MountEquipPart()
        {
            this._mountEquipMentList = new Vector.<OtherEquipItem>;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            var _loc_1:* = GlobalStyle.textFormatDanLan;
            _loc_1.size = 13;
            this._mountItemSp = UICompomentPool.getUICompoment(GSprite);
            this._mountItemSp.x = 0;
            this._mountItemSp.y = 0;
            this.addChild(this._mountItemSp);
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.MountEquipBg, 0, 0, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.MountEquipBg, 400, 0, this));
            this._mountGrouthItem = UICompomentPool.getUICompoment(BaseItem);
            this._mountGrouthItem.isSHowQuality = false;
            this._mountGrouthItem.isShowColorBg = false;
            this._mountGrouthItem.setItemStyle(ItemStyleConst.Small, ImagesConst.FashionEquipBg, 9, 9);
            this._mountGrouthItem.itemData = new ItemData(grouthItemCode);
            this._mountGrouthItem.x = 8;
            this._mountGrouthItem.y = 152;
            this._mountItemSp.addChild(this._mountGrouthItem);
            this._mountTalentItem = UICompomentPool.getUICompoment(BaseItem);
            this._mountTalentItem.isSHowQuality = false;
            this._mountTalentItem.isShowColorBg = false;
            this._mountTalentItem.setItemStyle(ItemStyleConst.Small, ImagesConst.FashionEquipBg, 9, 9);
            this._mountTalentItem.itemData = new ItemData(tatlentItemCode);
            this._mountTalentItem.x = 410;
            this._mountTalentItem.y = 152;
            this._mountItemSp.addChild(this._mountTalentItem);
            this._wardrobeEnterBtn = UIFactory.gLoadingButton(ResFileConst.WardrobeEnterBtn, 22, -25, 46, 23, this._mountItemSp);
            this._wardrobeEnterBtn.configEventListener(MouseEvent.CLICK, this.openWardrobeHandler);
            this._mountSharpItem = UICompomentPool.getUICompoment(OtherEquipItem);
            this._mountSharpItem.isSHowQuality = false;
            this._mountSharpItem.isShowColorBg = false;
            this._mountSharpItem.setItemStyle(ItemStyleConst.Small, ImagesConst.PrescriptionEquipBg, 10, 13);
            this._mountSharpItem.x = 13;
            this._mountSharpItem.y = -83;
            this._mountSharpItem.pos = 4;
            this._mountItemSp.addChild(this._mountSharpItem);
            this._mountGrouthUseBtn = UIFactory.gLoadedButton(ImagesConst.sub4_upSkin, this._mountGrouthItem.x + this._mountGrouthItem.width - 20, this._mountGrouthItem.y, 18, 18);
            this._mountGrouthUseBtn.configEventListener(MouseEvent.CLICK, this.useItemHandler);
            this._mountItemSp.addChild(this._mountGrouthUseBtn);
            this._mountTalentUseBtn = UIFactory.gLoadedButton(ImagesConst.sub4_upSkin, this._mountTalentItem.x + this._mountTalentItem.width - 20, this._mountTalentItem.y, 18, 18);
            this._mountTalentUseBtn.configEventListener(MouseEvent.CLICK, this.useItemHandler);
            this._mountItemSp.addChild(this._mountTalentUseBtn);
            this.createEquipList();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._wardrobeEnterBtn.dispose(param1);
            this._wardrobeEnterBtn = null;
            this._mountItemSp.dispose(param1);
            this._mountItemSp = null;
            this._mountGrouthItem.dispose(param1);
            this._mountGrouthItem = null;
            this._mountTalentItem.dispose(param1);
            this._mountTalentItem = null;
            this._mountGrouthUseBtn.dispose(param1);
            this._mountGrouthUseBtn = null;
            this._mountTalentUseBtn.dispose(param1);
            this._mountTalentUseBtn = null;
            this._mountSharpItem.dispose(param1);
            this._mountSharpItem = null;
            this._mountEquipMentList.length = 0;
            this._mountData = null;
            if (this._grouthOpenTips)
            {
                this._grouthOpenTips.dispose(param1);
                this._grouthOpenTips = null;
            }
            if (this._talentItemTips)
            {
                this._talentItemTips.dispose(param1);
                this._talentItemTips = null;
            }
            if (EquipBaseWin.isViewShow)
            {
                EquipBaseWin.instance.hide();
            }
            super.disposeImpl(param1);
            return;
        }// end function

        private function openWardrobeHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.WardrobeOpenWardrobe, EAdvanceComponentType._EAdvanceComponentTypeMount));
            return;
        }// end function

        private function createEquipList() : void
        {
            var _loc_1:OtherEquipItem = null;
            var _loc_2:int = 0;
            while (_loc_2 < 4)
            {
                
                _loc_1 = UICompomentPool.getUICompoment(OtherEquipItem);
                _loc_1.setItemStyle(ItemStyleConst.Small, ImagesConst.EquipItemBg, 7, 7);
                _loc_1.isAutoUpdateEquip(true, EGroup._EGroupProp, EProp._EPropMountEquip, _loc_2, EPlayerItemPosType._EPlayerItemPosTypeMount);
                _loc_1.isShowLock = true;
                _loc_1.buttonMode = true;
                _loc_1.x = 400 * (_loc_2 % 2) + 11;
                _loc_1.y = 60 * int(_loc_2 / 2) + 25;
                _loc_1.doubleClickEnabled = true;
                _loc_1.pos = _loc_2;
                _loc_1.configEventListener(MouseEvent.CLICK, this.openSmallWin);
                _loc_1.configEventListener(MouseEvent.DOUBLE_CLICK, this.putOffEquip);
                this.pushUIToDisposeVec(_loc_1);
                this._mountEquipMentList.push(_loc_1);
                this.addChild(_loc_1);
                _loc_2++;
            }
            this._mountEquipMentList.push(this._mountSharpItem);
            return;
        }// end function

        private function getSmallWinTitleData() : Dictionary
        {
            var _loc_1:* = new Dictionary();
            _loc_1[0] = [{name:"equip", label:Language.getString(35413)}];
            _loc_1[1] = [{name:"equip", label:Language.getString(35414)}];
            _loc_1[2] = [{name:"equip", label:Language.getString(35415)}];
            _loc_1[3] = [{name:"equip", label:Language.getString(35416)}];
            _loc_1[4] = [{name:"equip", label:Language.getString(35417)}];
            _loc_1[99] = [{name:"equip", label:Language.getString(35418)}];
            return _loc_1;
        }// end function

        private function openSmallWin(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as OtherEquipItem;
            var _loc_3:* = this.getSmallWinTitleData();
            EquipBaseWin.instance.setWinData(_loc_3, EPlayerItemPosType._EPlayerItemPosTypeMount, EGroup._EGroupProp, EProp._EPropMountEquip, _loc_2.pos);
            var _loc_4:* = this.localToGlobal(new Point(0, 0));
            EquipBaseWin.instance.show(_loc_4.x + 92, _loc_4.y);
            return;
        }// end function

        private function putOffEquip(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as OtherEquipItem;
            if (_loc_2.midLabel)
            {
                return;
            }
            var _loc_3:* = new Object();
            _loc_3.putonitemData = "";
            _loc_3.getoffItemData = Cache.instance.pack.mountPackCache.getEquipByType(_loc_2.pos);
            Dispatcher.dispatchEvent(new DataEvent(EventName.MountEquip, _loc_3));
            return;
        }// end function

        private function useItemHandler(event:MouseEvent) : void
        {
            var _loc_2:ItemData = null;
            var _loc_3:Array = null;
            if (event.currentTarget == this._mountGrouthUseBtn)
            {
                _loc_3 = Cache.instance.pack.backPackCache.getItemsByGroupCategoryAndType(EGroup._EGroupStuff, EStuff._EStuffAdvance, EAdvanceType._EAdvanceTypeMountGrowth);
                if (_loc_3 && _loc_3.length)
                {
                    _loc_2 = _loc_3[0] as ItemData;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.MountUseGrouthItem, _loc_2));
                }
            }
            else if (event.currentTarget == this._mountTalentUseBtn)
            {
                _loc_3 = Cache.instance.pack.backPackCache.getItemsByGroupCategoryAndType(EGroup._EGroupStuff, EStuff._EStuffAdvance, EAdvanceType._EAdvanceTypeMountTalent);
                if (_loc_3 && _loc_3.length)
                {
                    _loc_2 = _loc_3[0] as ItemData;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.MountUseTalentItem, _loc_2));
                }
            }
            return;
        }// end function

        private function changeSelected(event:Event) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.MountChangeSharp, null));
            return;
        }// end function

        public function updateEquip() : void
        {
            var _loc_1:ItemData = null;
            var _loc_2:OtherEquipItem = null;
            var _loc_4:int = 0;
            var _loc_3:int = 0;
            while (_loc_3 < 4)
            {
                
                _loc_2 = this._mountEquipMentList[_loc_3];
                _loc_1 = Cache.instance.pack.mountPackCache.getItemDataByType(_loc_3);
                if (_loc_1)
                {
                    _loc_2.itemData = _loc_1;
                    _loc_2.midLabel = "";
                    _loc_2.bitmapEnable = true;
                    _loc_2.updateStrengLevel(_loc_1.itemInfo.itemLevel);
                }
                else
                {
                    _loc_4 = getItemCodeByIndex(_loc_3);
                    if (_loc_4)
                    {
                        _loc_1 = new ItemData(_loc_4);
                    }
                    else
                    {
                        _loc_1 = null;
                    }
                    _loc_2.itemData = _loc_1;
                    _loc_2.midLabel = getItemNameByIndex(_loc_3);
                    _loc_2.bitmapEnable = false;
                    _loc_2.setColorBg(0);
                    _loc_2.clearStrengInfo();
                }
                _loc_3++;
            }
            return;
        }// end function

        public function updateMountSharpItem() : void
        {
            var _loc_1:* = Cache.instance.pack.mountPackCache.getItemByCode(this._mountData.sPublicMount.sharpId, true);
            if (_loc_1)
            {
                this._mountSharpItem.itemData = _loc_1;
                this._mountSharpItem.midLabel = "";
                this._mountSharpItem.bitmapEnable = true;
                this._mountSharpItem.updateStrengLevel(_loc_1.itemInfo.itemLevel);
            }
            else
            {
                this._mountSharpItem.itemData = null;
                this._mountSharpItem.midLabel = getItemNameByIndex(4);
                this._mountSharpItem.bitmapEnable = false;
                this._mountSharpItem.setColorBg(0);
                this._mountSharpItem.clearStrengInfo();
            }
            return;
        }// end function

        public function updateMountInfo(param1:MountData) : void
        {
            this._mountData = param1;
            if (this._mountData.sPublicMount.code >= 4)
            {
                this._mountGrouthItem.enabled = true;
                if (this._grouthOpenTips)
                {
                    this._grouthOpenTips.dispose();
                    this._grouthOpenTips = null;
                }
            }
            else
            {
                this._mountGrouthItem.enabled = false;
                if (this._grouthOpenTips == null)
                {
                    this._grouthOpenTips = UIFactory.gTextField(Language.getString(35338), this._mountGrouthItem.x + 2, this._mountGrouthItem.y + 57, 80, 20, this, GlobalStyle.textFormatHui);
                }
            }
            if (this._mountData.sPublicMount.code >= 5)
            {
                this._mountTalentItem.enabled = true;
                if (this._talentItemTips)
                {
                    this._talentItemTips.dispose();
                    this._talentItemTips = null;
                }
            }
            else
            {
                this._mountTalentItem.enabled = false;
                if (this._talentItemTips == null)
                {
                    this._talentItemTips = UIFactory.gTextField(Language.getString(35339), this._mountTalentItem.x + 3, this._mountTalentItem.y + 57, 80, 20, this, GlobalStyle.textFormatHui);
                }
            }
            this.updateMountItem();
            return;
        }// end function

        public function updateMountItem() : void
        {
            var _loc_1:* = Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(EGroup._EGroupStuff, EStuff._EStuffAdvance, EAdvanceType._EAdvanceTypeMountGrowth);
            var _loc_2:* = Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(EGroup._EGroupStuff, EStuff._EStuffAdvance, EAdvanceType._EAdvanceTypeMountTalent);
            if (_loc_1 > 0 && this._mountData.sPublicMount.code >= 4)
            {
                this._mountGrouthUseBtn.visible = true;
                EffectManager.glowFilterReg(this._mountGrouthUseBtn);
                this._mountGrouthItem.setAmountLabel(_loc_1 + "");
            }
            else
            {
                this._mountGrouthUseBtn.visible = false;
                EffectManager.glowFilterUnReg(this._mountGrouthUseBtn);
                this._mountGrouthItem.setAmountLabel("");
            }
            if (_loc_2 > 0 && this._mountData.mountLevel >= 5)
            {
                this._mountTalentUseBtn.visible = true;
                EffectManager.glowFilterReg(this._mountTalentUseBtn);
                this._mountTalentItem.setAmountLabel(_loc_2 + "");
            }
            else
            {
                this._mountTalentUseBtn.visible = false;
                EffectManager.glowFilterUnReg(this._mountTalentUseBtn);
                this._mountTalentItem.setAmountLabel("");
            }
            return;
        }// end function

        public function shapeCardStatUpdate() : void
        {
            return;
        }// end function

        public static function getItemNameByIndex(param1:int) : String
        {
            var _loc_2:String = null;
            switch(param1)
            {
                case 0:
                {
                    _loc_2 = Language.getString(35419);
                    break;
                }
                case 1:
                {
                    _loc_2 = Language.getString(35420);
                    break;
                }
                case 2:
                {
                    _loc_2 = Language.getString(35421);
                    break;
                }
                case 3:
                {
                    _loc_2 = Language.getString(35422);
                    break;
                }
                case 4:
                {
                    _loc_2 = Language.getString(35423);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

        public static function getItemCodeByIndex(param1:int) : int
        {
            var _loc_2:int = 0;
            switch(param1)
            {
                case 0:
                {
                    _loc_2 = 170000000;
                    break;
                }
                case 1:
                {
                    _loc_2 = 170010000;
                    break;
                }
                case 2:
                {
                    _loc_2 = 170020000;
                    break;
                }
                case 3:
                {
                    _loc_2 = 170030000;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

    }
}
